
window.onload = function () {
    findAll();
}

function addDiv() {
    $n("addDiv").style.visibility="visible"
}
function addStu() {
    $n("addDiv").style.visibility="hidden"
}

function findAll() {
    axios.get("/class/findAll").then(resp=>{
        var info = resp.data;
        var str="";
        info.forEach(n=>{
            str+= `<tr><td>${n.className}</td><td>${n.classDate}</td><td>${n.teacher}</td><td>
<input type="button" value="删除班级" style="margin-left:20px;height: 30px" onclick="del(${n.id})"></td></tr>`
        })
        $n("classData").innerHTML=str;
    });
}

function del(id) {
    axios.get("/class/del",{
        params:{
            id
        }
    }).then(resp=>{
        var info = resp.data;
        if (info=="ok"){
            findAll();
        }else {
            $n("infoDiv").style.visibility="visible"
        }
    })
}
function delInfo() {
    $n("infoDiv").style.visibility="hidden"
}
function add() {
    axios.get("/class/add",{
        params: {
            className:$n("addName").value,
            teacher:$n("addTeacher").value,
            classDate:$n("addDate").value
        }
    }).then(resp=>{
        var info = resp.data;
        if (info=="ok"){
            $n("addDiv").style.visibility="hidden"
            findAll();
        }
    })
}